package inits

import (
	"fmt"
	"golang-websocket-chatroom/global"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"gorm.io/gorm/logger"
)

func MysqlInit() {
	var err error
	dsn := "root:root@tcp(127.0.0.1:3306)/zhou?charset=utf8mb4&parseTime=True&loc=Local"
	global.DB, err = gorm.Open(mysql.Open(dsn), &gorm.Config{
		Logger: logger.Default.LogMode(logger.Info),
	})
	if err != nil {
		panic(err)
	} else {
		fmt.Println("数据库连接成功")
	}
}
